package com.easylive.web.controller;

import com.easylive.annotation.GlobalInterceptor;
import com.easylive.component.RedisComponent;
import com.easylive.entity.dto.TokenUserInfoDto;
import com.easylive.entity.enums.ResponseCodeEnum;
import com.easylive.entity.enums.VideoStatusEnum;
import com.easylive.entity.po.*;
import com.easylive.entity.query.*;
import com.easylive.entity.vo.PaginationResultVO;
import com.easylive.entity.vo.ResponseVO;
import com.easylive.entity.vo.VideoPostEditInfoVO;
import com.easylive.entity.vo.VideoStatusCountInfoVO;
import com.easylive.exception.BusinessException;
import com.easylive.service.*;
import com.easylive.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

@RestController
@RequestMapping("/ucenter")
@Validated
@Slf4j
public class UcenterInteractionController extends ABaseController{
    @Resource
    private RedisComponent redisComponent;
    @Resource
    private VideoInfoPostService videoInfoPostService;
    @Resource
    private VideoInfoFilePostService videoInfoFilePostService;
    @Resource
    private VideoInfoService videoInfoService;
    @Resource
    private VideoDanmuService videoDanmuService;

    @Resource
    private VideoCommentService videoCommentService;


    @RequestMapping("/loadAllVideo")
    @GlobalInterceptor(checkLogin = true)
    public ResponseVO loadAllVideo(){
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();

        VideoInfoQuery query = new VideoInfoQuery();
        query.setUserId(tokenUserInfoDto.getUserId());
        query.setOrderBy("create_time desc");
        List<VideoInfo> listByParam = videoInfoService.findListByParam(query);
        return getSuccessResponseVO(listByParam);

    }

    @RequestMapping("/loadComment")
    @GlobalInterceptor(checkLogin = true)
    public ResponseVO loadComment(Integer pageNo,
                                  String videoId){
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();
        VideoCommentQuery query = new VideoCommentQuery();
        query.setVideoId(videoId);
        query.setVideoUserId(tokenUserInfoDto.getUserId());
        query.setPageNo(pageNo);
        query.setOrderBy("comment_id desc");
        query.setQueryVideoInfo(true);
        PaginationResultVO<VideoComment> paginationResultVO = videoCommentService.findListByPage(query);

        return getSuccessResponseVO(paginationResultVO);

    }

    @RequestMapping("/delComment")
    @GlobalInterceptor(checkLogin = true)
    public ResponseVO delComment(@NotNull Integer commentId){
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();
        videoCommentService.deleteComment(commentId,tokenUserInfoDto.getUserId());
        return getSuccessResponseVO(null);


    }

    @RequestMapping("/loadDanmu")
    @GlobalInterceptor(checkLogin = true)
    public ResponseVO loadDanmu(Integer pageNo,
                                String videoId){
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();
        VideoDanmuQuery query = new VideoDanmuQuery();
        query.setVideoId(videoId);
        query.setVideoUserId(tokenUserInfoDto.getUserId());
        query.setOrderBy("danmu_id asc");
        query.setPageNo(pageNo);
        query.setQueryVideoInfo(true);
        PaginationResultVO<VideoDanmu> paginationResultVO = videoDanmuService.findListByPage(query);


        return getSuccessResponseVO(paginationResultVO);


    }

    @RequestMapping("/delDanmu")
    @GlobalInterceptor(checkLogin = true)
    public ResponseVO delDanmu(@NotNull Integer danmuId){
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();
        videoDanmuService.deleteDanmu(danmuId,tokenUserInfoDto.getUserId());


        return getSuccessResponseVO(null);


    }







}
